home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / tsoper / CT Explorer / MainForm.cs < prev    next >
Text File  |  2005-06-05  |  6KB  |  243 lines

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using PCIBird;
  8. using MyCustomControls;
  9.  
  10. //using Bluebit.MatrixLibrary; //maybe buy this full package later
  11.  
  12.  
  13.  
  14. namespace SampleGUI
  15. {
  16.     //list some definitions
  17.  
  18.     /// <summary>
  19.     /// Summary description for MainForm.
  20.     /// </summary>
  21.     public class MainForm : System.Windows.Forms.Form
  22.     {
  23.         /// <summary>
  24.         /// Required designer variable.
  25.         /// </summary> 
  26.         //Control Components
  27.         private System.ComponentModel.Container components = null;
  28.         public ViewPanel viewPanel;
  29.         private Label lbl_Position;
  30.         private Label lbl_;
  31.         private Button btn_TrackingSystem;
  32.         private Button btn_OpenFile;
  33.         public CTControlPanel ctControlPanel;
  34.         //public CustomControl1 cc1;
  35.         public ScrollSlider uc1;
  36.  
  37.         //tracking system objects
  38.         private TrackingSystem trackingSystem;
  39.         private bool    trackingSystemOnOff = false;
  40.         private bool    trackingSystemInitialized = false;
  41.  
  42.         public RichTextBox rtb = new RichTextBox();
  43.         public System.Windows.Forms.Form trackingForm;
  44.  
  45.         public MainForm()
  46.         {
  47.             //
  48.             // Required for Windows Form Designer support
  49.             //
  50.             InitializeComponent();
  51.  
  52.             //
  53.             // TODO: Add any constructor code after InitializeComponent call
  54.  
  55.             //add the main view panel
  56.             viewPanel = new ViewPanel();
  57.             viewPanel.BorderStyle = BorderStyle.Fixed3D;
  58.             Controls.Add( viewPanel );
  59.             
  60.  
  61.             // add the initialize tracking system button
  62.             btn_TrackingSystem = new Button();
  63.             btn_TrackingSystem.Text = "Initialize Tracking System";
  64.             btn_TrackingSystem.Size = new Size(150,30);
  65.             btn_TrackingSystem.Click += new EventHandler(HandleTrackingSystem);
  66.             Controls.Add( btn_TrackingSystem );
  67.  
  68.             lbl_Position = new Label();
  69.             lbl_Position.Location = new Point(10,100);
  70.             lbl_Position.Size = new Size(120,100);
  71.             Controls.Add( lbl_Position );
  72.  
  73.             btn_OpenFile = new Button();
  74.             btn_OpenFile.Location = new Point(0,50);
  75.             btn_OpenFile.Text = "Open File";
  76.             Controls.Add( btn_OpenFile );
  77.             btn_OpenFile.Click += new EventHandler(OpenFile_OnClick);
  78.  
  79.             lbl_ = new Label();
  80.             Controls.Add( lbl_ );
  81.             lbl_.Location = new Point(0,500);
  82.             lbl_.Size = new Size(200,200);
  83.             lbl_.Text = "Dummy Label";
  84.             viewPanel.mainSliceView.lbl = lbl_;
  85.  
  86.             ctControlPanel = new CTControlPanel();
  87.             ctControlPanel.Location = new Point(0,200);
  88.             ctControlPanel.Size = new Size(300,150);
  89.             Controls.Add(ctControlPanel);
  90.             ctControlPanel.Show();
  91.  
  92.             uc1 = new ScrollSlider();
  93.             uc1.Location = new Point(0,350);
  94.             //Controls.Add(uc1);
  95.  
  96.             //set the window up to start by calling resize callback
  97.             MainForm_Resize(new object(), new EventArgs());
  98.  
  99.             //set double buffering to ON
  100.             this.SetStyle(ControlStyles.DoubleBuffer,true);
  101.  
  102.             //Set up the tracking system
  103.             trackingSystem = new TrackingSystem();
  104.  
  105.             this.Resize += new EventHandler(MainForm_Resize);
  106.  
  107.         }
  108.  
  109.         void MainForm_Resize(object sender, EventArgs e)
  110.         {
  111.             int cx, cy;
  112.             Rectangle rect = new Rectangle();
  113.  
  114.             cx = this.ClientSize.Width;
  115.             cy = this.ClientSize.Height;
  116.             
  117.             rect.Width = cy > (int)(4/3.0*cx)? cx : (int)(3/4.0*cy);
  118.             rect.Height = (int)(4/3.0*rect.Width);
  119.  
  120.             
  121.             rect.X = cx - rect.Width;
  122.             rect.Y = 0;
  123.  
  124.             this.viewPanel.SetBounds(rect.X,rect.Y,rect.Width,
  125.                                 rect.Height);
  126.         }
  127.  
  128.         void HandleTrackingSystem(object sender, EventArgs e)
  129.         {
  130.             if(!trackingSystemInitialized)
  131.             {
  132.                 trackingSystem.Initialize();
  133.                 trackingSystemInitialized = true; //only initialized once
  134.                 btn_TrackingSystem.Text = "Start Tracking System";
  135.  
  136.                 TrackingSystemForm tsf = new TrackingSystemForm(trackingSystem);
  137.                 tsf.Show();
  138.                 return;
  139.             }
  140.  
  141.             if(trackingSystemOnOff)
  142.             {
  143.                 trackingSystemOnOff = false;
  144.                 btn_TrackingSystem.Text = "Start Tracking System";
  145.                 return;
  146.             }
  147.             else
  148.             {
  149.                 trackingSystemOnOff = true;
  150.                 btn_TrackingSystem.Text = "Stop Tracking System";
  151.                 while(trackingSystemOnOff)
  152.                 {
  153.                     PositionAnglesReading par = trackingSystem.sensor[0].GetAsyncReading();
  154.                     string str = "x:" + par.x + "\ny:" + par.y + "\nz:" + par.z + "\n";
  155.                     lbl_Position.Text = str;
  156.                     //viewPanel.SetPosition((float)par.x,(float)par.y,(float)par.z);
  157.                     viewPanel.Refresh();
  158.                 }
  159.             }    
  160.         }
  161.  
  162.         void OpenFile_OnClick(object sender, EventArgs e)
  163.         {
  164.             OpenFileDialog dlg = new OpenFileDialog();
  165.             dlg.DefaultExt = ".mhd";
  166.             dlg.Filter =    "Meta Files (*.mhd)|*.mhd|" +
  167.                             "DVD Files (*.dvd)|*.dvd|" +
  168.                             "Raw Files (*.raw)|*.raw";
  169.             dlg.InitialDirectory = "C:\\Documents and Settings\\Tim Soper\\My Documents\\"
  170.                                 + "CatheterScope Project\\CT Scans\\"; 
  171.             
  172.             if(dlg.ShowDialog() == DialogResult.OK)
  173.             {
  174.                 //close the file open browser
  175.                 dlg.Dispose();
  176.                 Application.DoEvents();
  177.  
  178.                 Scan scan = new Scan();
  179.                 scan.FilePath = dlg.FileName;
  180.                 int error = scan.Read();
  181.                 if(error.Equals(0))
  182.                 {
  183.                     viewPanel.mainSliceView.lbl = lbl_;
  184.                     viewPanel.LoadScan(scan);
  185.                     ctControlPanel.LinkToScan(scan);
  186.                     ctControlPanel.LinkToViewPanel(viewPanel);
  187.                     viewPanel.Refresh();
  188.                 }
  189.             }
  190.         
  191.         }
  192.     
  193.         /// <summary>
  194.         /// Clean up any resources being used.
  195.         /// </summary>
  196.         protected override void Dispose( bool disposing )
  197.         {
  198.             if( disposing )
  199.             {
  200.                 if (components != null) 
  201.                 {
  202.                     components.Dispose();
  203.                 }
  204.             }
  205.             base.Dispose( disposing );
  206.         }
  207.  
  208.         #region Windows Form Designer generated code
  209.         /// <summary>
  210.         /// Required method for Designer support - do not modify
  211.         /// the contents of this method with the code editor.
  212.         /// </summary>
  213.         private void InitializeComponent()
  214.         {
  215.             // 
  216.             // MainForm
  217.             // 
  218.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  219.             this.ClientSize = new System.Drawing.Size(592, 566);
  220.             this.Name = "MainForm";
  221.             this.Text = "Main Form";
  222.             this.Load += new System.EventHandler(this.MainForm_Load);
  223.  
  224.         }
  225.         #endregion
  226.  
  227.         /// <summary>
  228.         /// The main entry point for the application.
  229.         /// </summary>
  230.         [STAThread]
  231.         static void Main() 
  232.         {
  233.             MainForm mainForm = new MainForm();
  234.             Application.Run(mainForm);
  235.         }
  236.  
  237.         private void MainForm_Load(object sender, System.EventArgs e)
  238.         {
  239.         
  240.         }
  241.     }
  242. }
  243.